from django.core.management.base import BaseCommand, CommandError
import tsl_backend.frontend_api.models.workorder as workorders
import tsl_backend.frontend_api.models.order_routing as order_routing


class Command(BaseCommand):
    help = "Delete all orders"

    def add_arguments(self, parser):
        parser.add_argument("--delete", type=str)

    
    def handle(self, *args, **options):
        print(options)
        if options["delete"]=="all":
            workorders.ProductionActualBOM.objects.all().delete()
            workorders.ProductionStandardBOM.objects.all().delete()
            order_routing.ProductionRemarkAns.objects.all().delete()
            order_routing.QcFailed.objects.all().delete()
            order_routing.WorkerActionRecord.objects.all().delete()
            order_routing.Record.objects.all().delete()
            order_routing.WorkerRecord.objects.all().delete()
            order_routing.CheckRecord.objects.all().delete()
            order_routing.RouteDetail.objects.all().delete()
            order_routing.Dispatcher.objects.all().delete()


            order_routing.OrderRouting.objects.all().delete()
            workorders.Detail.objects.all().delete()

            self.stdout.write(
                self.style.SUCCESS('Successfully to delete all orders')
            )